package demogeric;

/**
 * 泛型类 ，包含一个方法 可以求最大值
 * @param <T>
 */
class Alg<T extends Comparable<T>> {
    public T findMax(T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            //if(array[i] > max) {
            if(array[i].compareTo(max) > 0 ) {
                max = array[i];
            }
        }
        return max;
    }
}

class Alg11<T extends Integer,K,V extends Number,P> {

}

class AlgT<T extends Number & Comparable<T> > {

}

class Alg2 {
    public <T extends Comparable<T>> T findMax(T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if(array[i].compareTo(max) > 0 ) {
                max = array[i];
            }
        }
        return max;
    }
}

class Alg3 {
    public static  <T extends Comparable<T>> T findMax(T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if(array[i].compareTo(max) > 0 ) {
                max = array[i];
            }
        }
        return max;
    }
}

public class Test {

    public static void main(String[] args) {
        Integer[] array = {1,3,21,15,8,17,6,9};
        int ret = Alg3.<Integer>findMax(array);
        System.out.println(ret);
    }

    public static void main2(String[] args) {
        Alg2 alg2 = new Alg2();
        Integer[] array = {1,3,21,15,8,17,6,9};
        alg2.<Integer>findMax(array);
        alg2.findMax(array);


    }
    public static void main1(String[] args) {
        Alg<Integer> alg1 = new Alg<>();
        Integer[] array = {1,3,21,15,8,17,6,9};
        int ret = alg1.findMax(array);
        System.out.println(ret);

        Alg<String> alg2 = new Alg<>();

        //demogeric.Alg<Student> alg3 = new demogeric.Alg<>();
    }
}

